<template>
  <div class="container" :class="{active:!isHome}">
    <!-- 首页头部 -->
    <Header v-if="isHome" v-bind:isBack="isBack" :title="title"></Header>
    <!-- 我的 头部-->
    <div class="header padding-24 space-between" v-if="!isHome">
      <div class="h-back" @click="goBack">
        <img :src="back" alt />
      </div>
      <div class="title">{{title1}}</div>
      <div class="h-right">
        <img :src="play" alt />
      </div>
    </div>
    <!-- 头部导航分类 -->
    <div class="header-nav" v-show="isHome">
      <div class="nav-list">
        <div
          class="item"
          v-for="(item,index) in headerNav"
          :key="index"
          :class="{active:item.audition_category_id == navIndex}"
          @click="checkType(item.audition_category_id)"
        >
          <div
            class="text fs-32"
            :class="{active:item.audition_category_id == navIndex}"
          >{{item.audition_category_name}}</div>
          <div class="line" v-show="item.audition_category_id == navIndex"></div>
        </div>
      </div>
    </div>
    <!-- 海选列表数据 -->
    <div class="sea-election" v-show="isHome">
      <div class="items" v-for="(item,index) in seaList" :key="index" @click="toDetails(item)">
        <div class="imgs">
          <img :src="item.audition_activity_cover" alt />
        </div>
        <div class="title fs-32">{{item.audition_activity_name}}</div>
        <div class="time fs-26">报名时间：{{item.enter_start_time}}-{{item.enter_end_time}}</div>
        <div class="vote fs-26">投票时间：{{item.vote_start_time}}-{{item.vote_end_time}}</div>
      </div>
    </div>
    <!-- 我的  --内容    -->
    <div class="mine-list" v-if="!isHome">
      <div class="support" @click="toMySupport">
        <div class="img">
          <img :src="support" alt />
        </div>
        <div class="text fs-32">支持的参赛者</div>
      </div>
      <div class="activity" @click="toMyActivity">
        <div class="img">
          <img :src="signUp" alt />
        </div>
        <div class="text fs-32">我报名的活动</div>
      </div>
      <div class="pay" @click="toBuyDetail">
        <div class="img">
          <img :src="minePay" alt />
        </div>
        <div class="text fs-32">购买记录</div>
      </div>
    </div>
    <!-- 海选底部 -->
    <div class="bottom">
      <div class="home" @click="toHome()">
        <div class="img">
          <img :src="isHome?homeActive:home" alt />
        </div>
        <div class="txt fs-22" :class="isHome?'active':''">首页</div>
      </div>
      <div class="mine" @click="toMine()">
        <div class="img">
          <img :src="isHome?mine:mineActive" alt />
        </div>
        <div class="txt fs-22" :class="isHome?'':'active'">我的</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "sea-election",
  data() {
    return {
      title: "MET海选",
      title1: "我的",
      isBack: true,
      isHome: true,
      isMine: true,
      home: require("@/assets/public/home.png"),
      mine: require("@/assets/public/mine.png"),
      homeActive: require("@/assets/public/home-active.png"),
      mineActive: require("@/assets/public/mine-active.png"),
      back: require("@/assets/index/back-mine.png"),
      play: require("@/assets/index/play-mine.png"),
      support: require("@/assets/index/support-mine.png"),
      signUp: require("@/assets/index/sign-up.png"),
      minePay: require("@/assets/index/mine-pay.png"),
      navIndex: 1,
      headerNav: [
        {
          id: 1,
          audition_category_name: "推荐"
        },
        {
          id: 2,
          audition_category_name: "LOOK直播"
        },
        {
          id: 3,
          text: "广场"
        },
        {
          id: 4,
          audition_category_name: "告白の夜"
        },
        {
          id: 5,
          audition_category_name: "翻唱"
        },
        {
          id: 6,
          audition_category_name: "广场"
        },
        {
          id: 7,
          text: "告白の夜"
        },
        {
          id: 8,
          audition_category_name: "翻唱"
        }
      ], //头部导航栏数据
      seaList: [], //海选列表数据
      category_id: 4,
    };
  },
  watch: {
    isHome: function(val) {}
  },
  components: {},
  methods: {
    // 我参加的活动的页面
    toMyActivity() {
      window.sessionStorage.setItem("isHome", false);
      this.$router.push({
        path: "/index/my-Activity",
        query: {}
      });
    },
    // 我支持的参赛者页面
    toMySupport() {
      window.sessionStorage.setItem("isHome", false);
      this.$router.push({
        path: "/index/my-support",
        query: {}
      });
    },
    // 购买记录页面
    toBuyDetail() {
      window.sessionStorage.setItem("isHome", false);
      this.$router.push({
        path: "/index/buy-detail",
        query: {}
      });
    },
    // 去海选活动详情页面
    toDetails(item) {
      this.$router.push({
        path: "/index/sea-activity",
        query: { id: item.audition_activity_vote_time_id }
      });
    },
    // 选择首页
    toHome() {
      this.isHome = true;
    },
    // 选择我的
    toMine() {
      this.isHome = false;
    },
    // 选择头部导航类型
    checkType(id) {
      this.navIndex = id;
      if (id == 1) {
        this.getSeaRecommend();
      } else {
        this.category_id = id;
        this.getSeaList();
      }
    },
    // 获取海选列表分类数据
    getSeaTypeList() {
      const url = this.$host1 + `home/audition/auditionCategory`;
      this.$axios
        .get(url)
        .then(res => {
          // console.log(res.data, "---res.data--");
          if (res.data.code == 200) {
            this.headerNav = res.data.data;
            this.headerNav.unshift({
              audition_category_id: 1,
              audition_category_name: "推荐"
            });
          } else {
            this.AlertWin(res.data.message);
          }
        })
        .catch(err => {
          console.log(err, "err-----");
        });
    },
    // 获取海选推荐列表的数据
    getSeaRecommend() {
      const url = this.$host1 + `home/audition/recommendAuditionActivityList`;
      this.$axios
        .get(url)
        .then(res => {
          // console.log(res.data, "---res.data--");
          if (res.data.code == 200) {
            this.seaList = res.data.data.list;
          } else {
            this.AlertWin(res.data.message);
          }
        })
        .catch(err => {
          console.log(err, "err-----");
        });
    },
    // 获取海选列表数据
    getSeaList() {
      const url =
        this.$host1 +
        `home/audition/auditionActivityListById?audition_category_id=` +
        this.category_id;
      this.$axios
        .get(url)
        .then(res => {
          // console.log(res.data, "---res.data--");
          if (res.data.code == 200) {
            this.seaList = res.data.data.list;
          } else {
            this.AlertWin(res.data.message);
          }
        })
        .catch(err => {
          console.log(err, "err-----");
        });
    },
    // 返回上一页
    goBack() {
      this.$router.go(-1);
    }
  },
  // beforeRouteEnter(to, from, next) {
  //   next(vm => {
  //     if (window.sessionStorage.getItem("isHome") == null) {
  //       vm.isHome = true;
  //     } else {
  //       vm.isHome = window.sessionStorage.getItem("isHome");
  //     }
  //   });
  // },
  created() {
    this.getSeaTypeList(); //获取海选分类列表数据
    this.getSeaRecommend(); //获取推荐数据
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
.container {
  padding-top: 2rem;
  box-sizing: border-box;
  &.active{
    padding-top: 1rem;
  }
  // 头部样式设置
  .header {
    .background {
      background-color: #f8f8f8;
    }
    .h-back {
      width: 0.15rem;
      height: 0.26rem;
      img {
        width: 100%;
      }
    }
    .title {
      font-size: 0.36rem;
      font-weight: bold;
      color: #444444;
    }
    .h-right {
      width: 0.38rem;
      height: 0.5rem;
      img {
        display: inline-block;
        width: 100%;
      }
    }
  }
  // 头部导航分类样式设置
  .header-nav {
    position: fixed;
    left: 0;
    top: 1rem;
    width: 100%;
    height: 1.02rem;
    line-height: 1.02rem;
    background-color: #fff;
    .nav-list {
      height: 1.02rem;
      padding: 0 0.24rem;
      box-sizing: border-box;
      display: flex;
      flex-direction: row;
      // justify-content: space-between;
      align-items: center;
      white-space: nowrap;
      overflow-x: auto;
      overflow-y: hidden;
      -webkit-overflow-scrolling: touch;
      .item {
        width: auto;
        margin-right: 0.64rem;
        height: 100%;
        position: relative;
        .text {
          font-weight: 500;
          color: rgba(68, 68, 68, 1);
        }
        .line {
          position: absolute;
          width: 100%;
          left: 0;
          bottom: 0;
          height: 0.05rem;
          border-radius: 0.03rem;
          background-color: #540479;
        }
      }
      .active {
        font-size: 0.36rem !important;
        font-weight: 800 !important;
        color: #540479 !important;
      }
    }
    .nav-list::-webkit-scrollbar {
      display: none;
    }
  }

  .sea-election {
    padding-bottom: 1rem;
    box-sizing: border-box;
    .items {
      padding: 0.44rem 0.25rem 0.34rem 0.23rem;
      box-sizing: border-box;
      background-color: #fff;
      .imgs {
        width: 7.02rem;
        height: 4rem;
        margin-bottom: 0.39rem;
        border-radius: 0.18rem;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .title {
        font-weight: 500;
        color: rgba(68, 68, 68, 1);
        line-height: 0.48rem;
      }
      .time,
      .vote {
        font-weight: 500;
        color: rgba(153, 153, 153, 1);
        line-height: 0.48rem;
      }
    }
  }

  .mine-list {
    .support,
    .activity,
    .pay {
      padding: 0.41rem 0 0.28rem 0.24rem;
      box-sizing: border-box;
      display: flex;
      background-color: #fff;
      border-bottom: 0.01rem solid #e9e9e9;
      .img {
        width: 0.42rem;
        height: 0.44rem;
        margin-right: 0.34rem;
        img {
          width: 100%;
        }
        .text {
          font-weight: 500;
          color: rgba(68, 68, 68, 1);
          line-height: 0.32rem;
        }
      }
    }
  }

  .bottom {
    width: 100%;
    position: fixed;
    left: 0;
    bottom: 0;
    height: 0.98rem;
    display: flex;
    align-items: center;
    justify-content: space-around;
    background-color: #fff;
    .home,
    .mine {
      .img {
        width: 0.4rem;
        height: 0.4rem;
        margin: 0 auto;
        margin-bottom: 0.09rem;
        img {
          width: 100%;
        }
      }
      .txt {
        font-weight: 500;
        color: rgba(102, 102, 102, 1);
        line-height: 0.32rem;
      }
    }
    .active {
      color: #540570 !important;
    }
  }
}

</style>
